package org.imlinker.plugin;

import java.util.ArrayList;

import org.jivesoftware.smack.Chat;
import org.jivesoftware.smack.packet.Message;

import org.imlinker.chat.PluginChat;
import org.imlinker.list.ViewList;
import org.imlinker.setting.Settings;

/**
 * The base class of plugin classes.It defined the methods that can be used in
 * plugin. 
 * 
 */

public class Plugin extends Object {

	/**
	 * 
	 */
	public static final String NOCHAT = "LINKERNOCHAT";

	/**
	 * Path.
	 */
	private String path;

	/**
	 * Plugin Item;
	 */
	private PluginItem item;

	/**
	 * 
	 * @param title
	 *            The plugin's title.
	 */
	public Plugin(final String title) {
	}

	/**
	 * Set path.
	 * 
	 * @param paraPath
	 *            The new path.
	 */
	public void setPath(final String paraPath) {
		this.path = paraPath;
	}

	/**
	 * 
	 * @return The path;
	 */
	public final String getPath() {
		return path;
	}

	/**
	 * Get element size by the given url.
	 * 
	 * @param url
	 *            The given url.
	 * @return The element size.
	 */
	public final int getElementSize(final String url) {

		return Settings.getSettings().getElementSize("plugin." + url);
	}

	/**
	 * 
	 */
	public final String getValue(String url) {
		return Settings.getSettings().getValue("plugin." + url);
	}

	public final void deleteValue(String url) {
		Settings.getSettings().deleteValue("plugin." + url);
	}

	public final void setValue(String u, String value) {
		Settings.getSettings().setValue("plugin." + u, value);
	}

	/**
	 * Get chat by given name.
	 * 
	 * @param buddy
	 *            The buddy's user name.
	 * @return The chat from the buddy's user.
	 */
	public final Chat getChat(final String buddy) {
		return ViewList.getBuddyList().getChat(buddy);
	}

	/**
	 * Add ChatListener to recieve the certain buddy's chat information.
	 * 
	 * @param buddy
	 *            The buddy who's chat to be listened.
	 */
	public final void addPluginChatListener(final String buddy) {
		// System.out.println("Add to chat hook!!! " + buddy);

		PluginChat.addChatListener(this, buddy);
	}

	/**
	 * Remove ChatListener form PluginChat.
	 * 
	 * @param buddy
	 *            The buddy who's chat remove listener.
	 */
	public final void removePluginChatListener(final String buddy) {
		PluginChat.removeChatListener(this, buddy);
	}

	/**
	 * Get buddy names.
	 * 
	 * @return The buddy's name.
	 */
	public final ArrayList getNames() {
		return ViewList.getBuddyList().getUsers();
	}

	/**
	 * 
	 * 
	 */
	public void doubleClick() {
		// TODO Auto-generated method stub

	}

	public String recieveChatMessage(Message message) {
		return null;
	}

	public void removeMessageNotifier() {
		ViewList.getMessageList().removeMessage(item);
	}

	public void addMessageNotifier() {
		ViewList.getMessageList().addMessage(item);
	}

	public void setPluginItem(PluginItem pluginItem) {
		item = pluginItem;
	}

}
